<!DOCTYPE html>
<html lang="zh-CN">
<head>
    <meta charset="UTF-8">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>并发编程：多线程设计模式与架构设计</title>
    <link rel="stylesheet" href="https://cdn.staticfile.org/font-awesome/6.4.0/css/all.min.css">
    <link rel="stylesheet" href="https://cdn.staticfile.org/tailwindcss/2.2.19/tailwind.min.css">
    <link href="https://fonts.googleapis.com/css2?family=Noto+Serif+SC:wght@400;500;600;700&family=Noto+Sans+SC:wght@300;400;500;700&display=swap" rel="stylesheet">
    <script src="https://cdn.jsdelivr.net/npm/mermaid@latest/dist/mermaid.min.js"></script>
    <style>
        body {
            font-family: 'Noto Sans SC', Tahoma, Arial, Roboto, "Droid Sans", "Helvetica Neue", "Droid Sans Fallback", "Heiti SC", "Hiragino Sans GB", Simsun, sans-serif;
            background: linear-gradient(135deg, #f5f7fa 0%, #c3cfe2 100%);
            min-height: 100vh;
        }
        
        /* Hero Section Animation */
        @keyframes fadeInUp {
            from {
                opacity: 0;
                transform: translateY(30px);
            }
            to {
                opacity: 1;
                transform: translateY(0);
            }
        }
        
        .hero-title {
            animation: fadeInUp 0.8s ease-out;
        }
        
        .hero-subtitle {
            animation: fadeInUp 0.8s ease-out 0.2s both;
        }
        
        .hero-description {
            animation: fadeInUp 0.8s ease-out 0.4s both;
        }
        
        /* Card Hover Effects */
        .card-hover {
            transition: all 0.3s ease;
        }
        
        .card-hover:hover {
            transform: translateY(-5px);
            box-shadow: 0 20px 40px rgba(0, 0, 0, 0.1);
        }
        
        /* Code Block Styling */
        pre {
            background: #1e293b;
            color: #e2e8f0;
            border-radius: 12px;
            padding: 1.5rem;
            overflow-x: auto;
            font-size: 14px;
            line-height: 1.6;
            box-shadow: 0 10px 30px rgba(0, 0, 0, 0.1);
        }
        
        code {
            font-family: 'Consolas', 'Monaco', 'Courier New', monospace;
        }
        
        /* Section Headers */
        .section-header {
            position: relative;
            padding-left: 1rem;
        }
        
        .section-header::before {
            content: '';
            position: absolute;
            left: 0;
            top: 50%;
            transform: translateY(-50%);
            width: 4px;
            height: 80%;
            background: linear-gradient(180deg, #3b82f6 0%, #8b5cf6 100%);
            border-radius: 2px;
        }
        
        /* Smooth Scroll */
        html {
            scroll-behavior: smooth;
        }
        
        /* Navigation Dots */
        .nav-dot {
            width: 12px;
            height: 12px;
            border-radius: 50%;
            background: #cbd5e1;
            transition: all 0.3s ease;
            cursor: pointer;
        }
        
        .nav-dot.active {
            background: #3b82f6;
            transform: scale(1.3);
        }
        
        /* Mermaid Diagram Container */
        .mermaid-container {
            background: white;
            border-radius: 12px;
            padding: 2rem;
            box-shadow: 0 10px 30px rgba(0, 0, 0, 0.05);
            margin: 2rem 0;
        }
        
        /* First Letter Drop Cap */
        .drop-cap::first-letter {
            float: left;
            font-size: 4rem;
            line-height: 3rem;
            padding-right: 0.5rem;
            margin-top: 0.5rem;
            font-weight: 700;
            color: #3b82f6;
            font-family: 'Noto Serif SC', serif;
        }
    </style>
</head>
<body>
    <!-- Hero Section -->
    <section class="relative overflow-hidden bg-gradient-to-br from-blue-600 via-purple-600 to-indigo-700 text-white">
        <div class="absolute inset-0 bg-black opacity-20"></div>
        <div class="relative container mx-auto px-6 py-24 text-center">
            <h1 class="hero-title text-5xl md:text-6xl font-bold mb-6">
                <i class="fas fa-network-wired mr-4"></i>并发编程的艺术
            </h1>
            <h2 class="hero-subtitle text-2xl md:text-3xl font-light mb-8">
                多线程设计模式与架构设计深度解析
            </h2>
            <p class="hero-description text-lg md:text-xl max-w-3xl mx-auto opacity-90">
                探索现代应用程序中的并发编程技术，掌握多线程设计模式的精髓，构建高效、稳定的并发系统架构
            </p>
        </div>
        <div class="absolute bottom-0 left-0 right-0">
            <svg viewBox="0 0 1440 120" fill="none" xmlns="http://www.w3.org/2000/svg">
                <path d="M0 120L60 110C120 100 240 80 360 70C480 60 600 60 720 65C840 70 960 80 1080 85C1200 90 1320 90 1380 90L1440 90V120H1380C1320 120 1200 120 1080 120C960 120 840 120 720 120C600 120 480 120 360 120C240 120 120 120 60 120H0V120Z" fill="white"/>
            </svg>
        </div>
    </section>

    <!-- Navigation Sidebar -->
    <div class="fixed right-8 top-1/2 transform -translate-y-1/2 z-50 hidden lg:block">
        <div class="space-y-4">
            <div class="nav-dot active" onclick="scrollToSection('intro')"></div>
            <div class="nav-dot" onclick="scrollToSection('concepts')"></div>
            <div class="nav-dot" onclick="scrollToSection('patterns')"></div>
            <div class="nav-dot" onclick="scrollToSection('architecture')"></div>
            <div class="nav-dot" onclick="scrollToSection('optimization')"></div>
        </div>
    </div>

    <!-- Main Content -->
    <main class="container mx-auto px-6 py-12">
        <!-- Introduction Section -->
        <section id="intro" class="mb-16">
            <div class="bg-white rounded-2xl shadow-xl p-8 md:p-12">
                <p class="text-lg leading-relaxed text-gray-700 drop-cap">
                    随着现代应用程序的复杂度不断增加，并发编程成为高效设计和实现系统的关键技术之一。尤其是在涉及到大量并发请求、高负载处理时，多线程技术不可避免地成为解决性能瓶颈的有效手段。然而，单纯的多线程编程并不足以保证系统的稳定性和高效性。为了高效管理多线程和并发操作，设计模式和架构设计的作用变得愈加重要。
                </p>
            </div>
        </section>

        <!-- Concepts and Challenges -->
        <section id="concepts" class="mb-16">
            <h2 class="section-header text-3xl font-bold mb-8 text-gray-800">
                <i class="fas fa-lightbulb text-yellow-500 mr-3"></i>1. 并发编程的基本概念与挑战
            </h2>
            
            <div class="grid md:grid-cols-2 gap-8">
                <div class="bg-white rounded-xl shadow-lg p-8 card-hover">
                    <h3 class="text-xl font-semibold mb-4 text-blue-600">
                        <i class="fas fa-book mr-2"></i>1.1 并发编程的基本概念
                    </h3>
                    <p class="text-gray-700 leading-relaxed">
                        并发编程是指在同一时间段内，多个任务在同一个处理器或多个处理器上并行执行的技术。它主要解决如何利用计算机多核处理器，提高程序执行效率的问题。在 Java 中，基于多线程的并发编程模式非常常见。多线程允许在同一进程中同时执行多个线程，每个线程相互独立，执行不同的任务。
                    </p>
                </div>
                
                <div class="bg-white rounded-xl shadow-lg p-8 card-hover">
                    <h3 class="text-xl font-semibold mb-4 text-purple-600">
                        <i class="fas fa-exclamation-triangle mr-2"></i>1.2 并发编程面临的挑战
                    </h3>
                    <p class="text-gray-700 leading-relaxed mb-4">
                        并发编程虽然可以提高性能，但同时带来了多线程管理、线程安全、死锁等问题，开发者需要采取有效的措施来应对这些挑战。常见的挑战包括：
                    </p>
                </div>
            </div>

            <!-- Challenges Grid -->
            <div class="grid md:grid-cols-2 lg:grid-cols-4 gap-6 mt-8">
                <div class="bg-gradient-to-br from-red-50 to-red-100 rounded-lg p-6 card-hover">
                    <i class="fas fa-lock text-red-500 text-3xl mb-3"></i>
                    <h4 class="font-semibold text-gray-800 mb-2">线程安全问题</h4>
                    <p class="text-sm text-gray-600">多个线程并发访问共享资源时，容易发生数据不一致的情况。</p>
                </div>
                <div class="bg-gradient-to-br from-orange-50 to-orange-100 rounded-lg p-6 card-hover">
                    <i class="fas fa-skull-crossbones text-orange-500 text-3xl mb-3"></i>
                    <h4 class="font-semibold text-gray-800 mb-2">死锁问题</h4>
                    <p class="text-sm text-gray-600">多个线程因相互依赖的资源而进入互相等待的状态，导致程序无法继续执行。</p>
                </div>
                <div class="bg-gradient-to-br from-yellow-50 to-yellow-100 rounded-lg p-6 card-hover">
                    <i class="fas fa-exchange-alt text-yellow-500 text-3xl mb-3"></i>
                    <h4 class="font-semibold text-gray-800 mb-2">上下文切换开销</h4>
                    <p class="text-sm text-gray-600">频繁的线程切换会带来性能损失。</p>
                </div>
                <div class="bg-gradient-to-br from-green-50 to-green-100 rounded-lg p-6 card-hover">
                    <i class="fas fa-tasks text-green-500 text-3xl mb-3"></i>
                    <h4 class="font-semibold text-gray-800 mb-2">资源管理</h4>
                    <p class="text-sm text-gray-600">线程池、任务调度等资源的合理分配与管理。</p>
                </div>
            </div>
        </section>

        <!-- Design Patterns Section -->
        <section id="patterns" class="mb-16">
            <h2 class="section-header text-3xl font-bold mb-8 text-gray-800">
                <i class="fas fa-puzzle-piece text-blue-500 mr-3"></i>2. 多线程设计模式
            </h2>

            <!-- Pattern Cards -->
            <div class="space-y-8">
                <!-- Singleton Pattern -->
                <div class="bg-white rounded-xl shadow-lg overflow-hidden">
                    <div class="bg-gradient-to-r from-blue-500 to-blue-600 text-white p-6">
                        <h3 class="text-2xl font-semibold">
                            <i class="fas fa-cube mr-3"></i>2.1 单例模式（Singleton Pattern）
                        </h3>
                    </div>
                    <div class="p-8">
                        <p class="text-gray-700 leading-relaxed mb-6">
                            在并发编程中，单例模式用于确保在整个系统中，某个类只有一个实例。这对于管理共享资源或全局状态非常有用。在多线程环境下，单例模式需要考虑线程安全的问题。Java 提供了多种实现单例模式的方式，其中最常用的是"双重检查锁"模式（Double-Checked Locking）：
                        </p>
                        <pre><code>public class Singleton {
    private static volatile Singleton instance;

    private Singleton() {}

    public static Singleton getInstance() {
        if (instance == null) {
            synchronized (Singleton.class) {
                if (instance == null) {
                    instance = new Singleton();
                }
            }
        }
        return instance;
    }
}</code></pre>
                        <p class="text-gray-700 mt-6">
                            在这个实现中，<code class="bg-gray-100 px-2 py-1 rounded text-sm">volatile</code> 关键字确保了多线程环境下的内存可见性，避免了创建多个实例的情况。
                        </p>
                    </div>
                </div>

                <!-- Producer-Consumer Pattern -->
                <div class="bg-white rounded-xl shadow-lg overflow-hidden">
                    <div class="bg-gradient-to-r from-purple-500 to-purple-600 text-white p-6">
                        <h3 class="text-2xl font-semibold">
                            <i class="fas fa-sync-alt mr-3"></i>2.2 生产者-消